# coding=utf-8

import qiniu
access_key = 'P1fMu1lQL3qOWaD5dMOi2K81GjHBNxGOLmGZANj4'
secret_key = '7DdulCnAeNiWOMbZOwnUTCihMr3w_ULCV4wh6jLI'
bucket_name = 'ais0073'
def image_storage(data):
    q = qiniu.Auth(access_key, secret_key)
    token = q.upload_token(bucket_name)
    ret, info = qiniu.put_data(token, None, data)
    if info.status_code == 200:
        key = ret.get('key')
        return key
    else:
        raise Exception('上传图片失败')

if __name__ == '__main__':
    file_name = raw_input('请输入要上传的图片:')

    with open(file_name,'rb') as f:
        image_storage(f.read())